import 'package:flutter/material.dart';

class ScrollPage extends StatefulWidget {
  const ScrollPage({Key key}) : super(key: key);

  @override
  _ScrollPageState createState() => _ScrollPageState();
}

class _ScrollPageState extends State<ScrollPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            expandedHeight: 200.0,
            flexibleSpace: FlexibleSpaceBar(
              // title: Text('SliverAppBar'),
              background: Image.network(
                'https://www.itying.com/images/flutter/4.png',
                fit: BoxFit.cover,
              ),
            ),
            pinned: true,
            title: Text('SliverAppBar'),
          ),
          SliverToBoxAdapter(
            child: Container(
              height: 100.0,
              color: Colors.red,
              child: Center(
                child: Text('SliverToBoxAdapter'),
              ),
            ),
          ),
          SliverList(
            delegate: SliverChildBuilderDelegate(
              (BuildContext context, int index) {
                return Container(
                  height: 50.0,
                  color: index.isOdd ? Colors.white : Colors.blue[200],
                  child: Center(
                    child: Text('Item $index'),
                  ),
                );
              },
              childCount: 20,
            ),
          ),
          SliverGrid(
            delegate: SliverChildBuilderDelegate(
              (BuildContext context, int index) {
                return Container(
                  color: Colors.green[100 * (index % 9)],
                  child: Center(
                    child: Text('Grid Item $index'),
                  ),
                );
              },
              childCount: 20,
            ),
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 2,
              mainAxisSpacing: 10.0,
              crossAxisSpacing: 10.0,
              childAspectRatio: 1.0,
            ),
          ),
        ],
      ),
    );
  }
}
